<?php
$searchFor = mysql_real_escape_string($_POST['search_for']);
$searchQuery = mysql_query("SELECT * FROM `album` WHERE `artist` LIKE '%$searchFor%' ") or die(mysql_error());
?>
Artists:<br />
<?php
while ($searchResult = mysql_fetch_array($searchQuery)) {
	?><?=$searchResult[artist]?> -- "<a href="?cat=<?=$cat?>&amp;mode=cdview&amp;cddbid=<?=$searchResult[cddbid]?>"><?=$searchResult[title]?></a>"
	<?php
   if ($U_[rights] > 3) {
	   ?>
	   <a href="?mode=cdedit&amp;cddbid=<?=$searchResult[cddbid]?>&amp;cat=<?=$cat?>" title="Edit this CD"><img 
	   style="border: 0px;" height="16" width="16" title="Edit this CD" alt="edit this CD" 
	   src="./themes/<?=$theme?>/img/edit.png" /></a><a
	   onClick="delAlbum(<?php echo($searchResult[cddbid]) ?>)"> (delete)</a><br /><?php   
   }
}
$compAlbQuery = mysql_query("SELECT `cddbid` FROM `album` WHERE `is_comp` = '1' ");
while ($compAlb = mysql_fetch_row($compAlbQuery)) {
   $searchQuery = mysql_query("SELECT * FROM `track` WHERE (`cddbid` = '".$compAlb[0]."') AND (`artist` LIKE '%$searchFor%') ") or die(mysql_error());
} 
while ($searchResult = mysql_fetch_array($searchQuery)) {
	$albumName = mysql_fetch_array(mysql_query("SELECT `title` FROM `album` WHERE `cddbid`='".mysql_real_escape_string($searchResult[cddbid])."' "));
	echo($searchResult[artist] . '-- "<a href="?cat=' . $cat . '&mode=cdview&cddbid=' . $searchResult[cddbid] . '">' . $albumName[0]  . '</a>"<br />');
}
?>
<br /><br />
Albums:<br />
<?php
$searchQuery = mysql_query("SELECT * FROM `album` WHERE `title` LIKE '%$searchFor%' ") or die(mysql_error());
while ($searchResult = mysql_fetch_array($searchQuery)) {
	echo('"<a href="?cat=' . $cat . '&mode=cdview&cddbid=' . $searchResult[cddbid] . '">' . $searchResult[title] . '</a>" by ' . $searchResult[artist] . '<br />');
}
?><br /><br />
Tracks: <br />
<?php
while ($searchResult = mysql_fetch_array($searchQuery)) {
	echo($searchResult[artist] . ' -- "' .$searchResult[title] . '"<br />');
}
$searchQuery = mysql_query("SELECT * FROM `track` WHERE `title` LIKE '%$searchFor%' ") or die(mysql_error()); 
while ($searchResult = mysql_fetch_array($searchQuery)) {
	$albumName = mysql_fetch_array(mysql_query("SELECT `title`,`artist` FROM `album` WHERE `cddbid`='".mysql_real_escape_string($searchResult[cddbid])."' "));
	if (!$searchResult[artist]) $searchResult[artist] = $albumName[artist];
	echo('"' . $searchResult[title] . '" from "<a href="?cat=' . $cat . '&mode=cdview&cddbid=' . $searchResult[cddbid] . '">' . $albumName[0] . '</a>" by ' . $searchResult[artist] . '<br />');
}
?>